#pragma once

#include <iostream>
#include <string>
#include <functional>
#include <vector>
#include <list>
#include <memory>

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

using namespace std;

#define     TEST_MOVE           0

/**             移动语义构造
 *
 */
namespace Move
{
    class Object
    {
    public:
        Object(int num=8)
        {
            std::cout <<"Object(int)" << endl;
            m_num = num;
        }

        ~Object()
        {
            std::cout << __PRETTY_FUNCTION__ << endl;
        }

        // 构造函数
        Object(Object &obj)
        {
            cout << "Copy = (Object &) " << endl;
        }

        // 移动构造函数, 使用二级引用, 实现移动构造函数的类, 使用std::move后节省内存拷贝
        Object(Object &&obj)
        {
            cout << "Copy - (Object &&) " << endl;
        }

        Object(const Object *obj)
        {
            cout << "Copy > (const Object *) " << endl;
        }

        Object &operator=(const Object &obj)
        {
            cout << "operator= " << endl;
            return *this;
        }

        int m_num = 0;
    };


    class String
    {
    public:
        String()
        {
            std::cout << __PRETTY_FUNCTION__ << endl;
            m_pBuf = new char[128];
            memset(m_pBuf, 0, 128);
        }

        String(const char *p)
        {
            (void)p;
            std::cout << __PRETTY_FUNCTION__ << endl;
        }

        ~String()
        {
            std::cout << __PRETTY_FUNCTION__ << endl;
            if ( m_pBuf != nullptr )
            {
                delete [] m_pBuf;
                m_pBuf = nullptr;
            }
        }

        //拷贝构造函数
        String(const String &str)
        {
            (void)str;
            std::cout << "Copy String" << endl;
        }

        //移动构造函数
        String(String &&str)
        {
            (void)str;
            std::cout << "Move String" << endl;
        }

        // 赋值构造函数
        String &operator=(const String &str)
        {
            (void)str;
            std::cout << __PRETTY_FUNCTION__ << endl;
            return *this;
        }

    private:
        char *m_pBuf = nullptr;

    };

}




